home *** CD-ROM | disk | FTP | other *** search
- Path: trib.apple.com!usenet
- From: Amir <Amir@bayarea.net>
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: H E L P
- Date: Thu, 04 Apr 1996 10:52:56 -0700
- Organization: Apple Computer, Inc., Cupertino, California
- Message-ID: <31640C78.56DE@bayarea.net>
- References: <N.040296.013047.18@DynamicPPP-185.HIP.CAM.ORG> <Pine.A32.3.91.960402135001.121719B-100000@green.weeg.uiowa.edu> <4js6jh$ndr@solutions.solon.com> <DpAx1J.4n9@iquest.net>
- NNTP-Posting-Host: 17.128.203.75
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (Macintosh; I; PPC)
-
- Doug Miller wrote:
- >
- > seebs@solutions.solon.com (Peter Seebach) wrote:
- > >In article <Pine.A32.3.91.960402135001.121719B-100000@green.weeg.uiowa.edu>,
- > >The Amorphous Mass <robinson@blue.weeg.uiowa.edu> wrote:
- > >>On Tue, 2 Apr 1996 ramrod@cam.org wrote:
- > >
- > >>> The part that I am having a hard time with is the part that
- > >>> whatever number I enter for the age, I'm supposed to get the same number
- > >>> of happy faces, automatically. For example If I say I am 45 years old,
- > >>> then the program should show 45 happy faces.
- > >
- > >> You need a loop. Look up the for, while, and do while loop constructs in
- > >>your textbook.
- > >
- > >This is a bit strong. You don't *need* a loop. You just probably want one.
- > >
- > >Obviously, if you're assuming age, you would have no more than about 150 ifs
- > >to test, (assuming humans), and if you just want to do it for 45, it's even
- > >easier.
- > >
- >
- > Obviously you didn't read what he wrote. To satisfy the conditions of the task as he stated it,
- > he would need an infinite number of ifs ("whatever number I enter..."). I saw nothing in his
- > statement of the task that placed any limits of any sort on the number -- thus, he *does* need
- > a loop.
-
- I agree with Peter, "whatever number I enter for the age",
- means it is not infinite number but constrained by the max
- age limit (150 seems quit safe).
-
- 1. You can use loop.
- 2. you can use recursion, just one var in the stack, seems
- safe for max 150 level deep:
-
- void printAge(int age)
- {
- if (age > 0)
- {
- printf("X");
- printAge(age -1);
- }
- else
- printf("\n");
- }
-
- 3. You can prepare a buffer of happy faces and just print
- it, e.g.:
-
- buf[150] = "\x01\x01\x01\x01 <--150 times --> \x01"
- ....
- buf[age] = '\0';
- printf("%s/n",buf);
- buf[age] = '\1';
-
-
-
-
- --
- -- o o
- -----ooo---O---ooo-----------------------------------------
- -- Amir Deutel
- --
- -- Home: Amir@bayarea.net http://www.bayarea.net/~amir/
- -- Work: Amir_Deutel@powertalk.apple.com
-